package com.lc202310;

import java.util.PriorityQueue;

/**
 * Description:
 *
 * @Create 2023/10/18 21:02
 * @Version 1.0
 */
public class Solution1890 {
    public long maxKelements(int[] nums, int k) {
        PriorityQueue<Integer> queue = new PriorityQueue<>((o1, o2) -> o2 - o1);
        for (int num : nums) {
            queue.offer(num);
        }
        long res = 0L;
        for (int i = 0; i < k; i++) {
            int max = queue.poll();
            if (max == 1) {
                return res + k - i;
            }
            res+=max;
            queue.offer((max+2)/3);
        }
        return res;
    }
}
